/*
 * @lc app=leetcode.cn id=237 lang=typescript
 *
 * [237] 删除链表中的节点
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * class ListNode {
 *     val: number
 *     next: ListNode | null
 *     constructor(val?: number, next?: ListNode | null) {
 *         this.val = (val===undefined ? 0 : val)
 *         this.next = (next===undefined ? null : next)
 *     }
 * }
 */

/**
 Do not return anything, modify it in-place instead.
 */
//  思路：替换值和next指向
//  复杂度：O(1) O(1)

function deleteNode(root: ListNode | null): void {
    if (!root) return
    root.val = root.next!.val
    root.next = root.next!.next
};
// @lc code=end

import { ListNode } from "./type"
let head = new ListNode(4)
let node2 = new ListNode(5)
let node3 = new ListNode(1)
let node4 = new ListNode(9)

head.next = node2
node2.next = node3
node3.next = node4

deleteNode(node2)
console.log(ListNode.printList(head))
